# coding:utf-8

int_data = 12
float_data = 3.14

str_int_data = str(int_data)
str_float_data = str(float_data)
print(str_int_data, str_float_data, type(str_int_data), type(str_float_data))  # 12 3.14 <class 'str'> <class 'str'>

zero_number = 0
_number = -1

str_zero_number = str(zero_number)
str_number = str(_number)
print(str_zero_number, str_number, type(str_zero_number), type(str_number))  # 0 -1 <class 'str'> <class 'str'>

str_float = '3.14'
str_int = '123456'

real_float = float(str_float)
real_int = int(str_int)

print(real_float, real_int, type(real_float), type(real_int))  # 3.14 123456 <class 'float'> <class 'int'>

# int()、float()不能转换混合类型的字符串
mix_str = '123a'
# print(int(mix_str))  # ValueError: invalid literal for int() with base 10: '123a'

float_data_str = '3.14'
test_data = float(float_data_str)
print(test_data, type(test_data))  # 3.14 <class 'float'>

# int()不能转换浮点数的字符串
# float_data_str2 = '3.1415'
# test_data = int(float_data_str2)
# print(test_data, type(test_data))   # ValueError: invalid literal for int() with base 10: '3.1415'

int_data_str = '123'
test_data = float(int_data_str)
print(test_data, type(test_data))  # 123.0 <class 'float'>
